<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>try...catch 语句</title>
    <script>
        var txt = "";
        function message() {
            try {
                adddlert("Welcome guest!");
            }
            catch (err) {
                txt = "本页有一个错误。\n\n";
                txt += "错误描述：" + err.message + "\n\n";
                txt += "点击确定继续。\n\n";
                alert(txt);
            }
        }
    </script>
</head>

<body>
    <input type="button" value="查看消息" onclick="message()" />
</body>

</html>